package com.qimei.onerice.until;

import java.sql.*;

public class DBUtil {
	private static final String url = "jdbc:mysql://localhost/onerice?allowPublicKeyRetrieval=true&useSSL=false&serverTimezone=Asia/Shanghai";
	private static final String user = "root";
	private static final String password="123456";
	/**
	 * 获取数据库连接
	 */
	public static Connection getConnection()  {
		// 获取连接,URL
		Connection con = null;
		try {
			Class.forName("com.mysql.cj.jdbc.Driver");
			con = DriverManager.getConnection(url, user, password);
		} catch (SQLException | ClassNotFoundException e) {
			e.printStackTrace();
		}
		return con;
	}
	/**
	 * * 释放JDBC相关资源
	 * @param rs
	 * @param st
	 * @param conn
	 */
	public static void release(ResultSet rs, Statement st, Connection conn) {
		if(rs != null) {
			try {
				rs.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}

		if(st != null) {
			try {
				st.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}

		if(conn != null) {
			try {
				conn.close();
			} catch (SQLException e) {
				e.printStackTrace();
			}
		}
	}

}
